package net.cohoivang.news;

import java.util.Date;
import java.util.LinkedList;

import net.cohoivang.core.Industry;
import net.cohoivang.core.Sector;
import net.cohoivang.user.MyLanguages;

public class News implements INews {
	private int newsId;
	private NewsCategory newsCategory;
	private String title;
	private String description;
	private String content;
	private String filePath;
	
	private String source;
	private String image;
	private Industry indtustry;
	private Sector sector;
	private MyLanguages lang;	
	
	private float originalPrice;
	private float currentPrice;
	private float percentSafe;
	private float changePrice;
	
	private final RecordStatus recordStatus;
		
	
	LinkedList<EnableToTopListener> listener = new LinkedList<EnableToTopListener>();	
	
	public News(int newsId, Date createDate, String createBy, Date lastUpdateDate,
			String lastUpdateBy, int isReviewed, int isTop, int expireTime, int currentTime) {
		this.newsId = newsId;	
		recordStatus = new RecordStatus();
		recordStatus.createDate = createDate;
		recordStatus.createBy = createBy;
		recordStatus.lastUpdateDate = lastUpdateDate;
		recordStatus.lastUpdateBy = lastUpdateBy;
		recordStatus.isReviewed = isReviewed;
		recordStatus.isTop = isTop;
		recordStatus.expiredTime = expireTime;
		recordStatus.currentTime = currentTime;
	}
	
	public boolean isCurrentTop() {
		if (recordStatus.isTop == 1 && recordStatus.isReviewed == 1 && recordStatus.currentTime != 0) {
			return true;
		}
		return false;
	}
	public int getNewsId() {
		return newsId;
	}
	public void setNewsId(int newsId) {
		this.newsId = newsId;
	}
	public NewsCategory getNewsCategory() {
		return newsCategory;
	}
	public void setNewsCategory(NewsCategory newsCategory) {
		this.newsCategory = newsCategory;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getFilePath() {
		return filePath;
	}
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	public String getSource() {
		return source;
	}
	public void setSource(String source) {
		this.source = source;
	}
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
	public Industry getIndtustry() {
		return indtustry;
	}
	public void setIndtustry(Industry indtustry) {
		this.indtustry = indtustry;
	}
	public Sector getSector() {
		return sector;
	}
	public void setSector(Sector sector) {
		this.sector = sector;
	}
	
	
	public void setLang(MyLanguages lang) {
		this.lang = lang;
	}
	
	public RecordStatus getRecordStatus() {
		return recordStatus;
	}
	
	public void addEnableToTopListener(EnableToTopListener l) {
		this.listener.add(l);
	}
	public float getOriginalPrice() {
		return originalPrice;
	}
	public void setOriginalPrice(float originalPrice) {
		this.originalPrice = originalPrice;
	}
	public float getCurrentPrice() {
		return currentPrice;
	}
	public void setCurrentPrice(float currentPrice) {
		this.currentPrice = currentPrice;
	}
	public float getPercentSafe() {
		return percentSafe;
	}
	public void setPercentSafe(float percentSafe) {
		this.percentSafe = percentSafe;
	}
	public float getChangePrice() {
		return changePrice;
	}
	public void setChangePrice(float changePrice) {
		this.changePrice = changePrice;
	}
	public MyLanguages getLang() {
		return lang;
	}

	@Override
	public int processExpireTime(int usedTime) {
		if (this.recordStatus.currentTime - usedTime > 0) {
			this.recordStatus.currentTime -= usedTime;
		} else {
			this.recordStatus.currentTime = 0;
		}
		return this.recordStatus.currentTime;		
	}
	
	public boolean isAvailable() {
		if (this.recordStatus.isReviewed == 1 && this.recordStatus.currentTime != 0) {
			return true;
		}
		return false;
	}

	@Override
	public LinkedList<EnableToTopListener> getEnableToTopListListeners() {
		return listener;
	}

	@Override
	public boolean isTop() {
		// TODO Auto-generated method stub
		return this.isCurrentTop();
	}

	@Override
	public Date getICreateDate() {
		// TODO Auto-generated method stub
		return getRecordStatus().createDate;
	}

	@Override
	public Date getILastUpdateDate() {
		// TODO Auto-generated method stub
		return getRecordStatus().lastUpdateDate;
	}	
		
}
